require 'login_system'

# Filters added to this controller will be run for all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
  # Pick a unique cookie name to distinguish our session data from others'
  # session :session_key => '_ptm_session_id'
  self.allow_forgery_protection = false
  layout 'general'
  include LoginSystem
  before_filter :disable_link_prefetching

  auto_complete_for :task, :title
  
  def auto_complete_for_task_title
    re = Regexp.new("#{params[:task][:title]}", "i")
    p_ids = session['user'].active_projects_ids.join(',')
    render :nothing=>true and return if p_ids == ''
    @tasks = Task.find(:all,:conditions=>"project_id in (#{p_ids})").collect(&:title).select { |t| re.match t }.sort
    render :inline => "<%= content_tag(:ul, @tasks.map { |t| content_tag(:li, h(t)) }) %>"
  end

private

   def disable_link_prefetching
      if request.env["HTTP_X_MOZ"] == "prefetch" 
         logger.debug "prefetch detected: sending 403 Forbidden" 
         render_nothing "403 Forbidden" 
         return false
      end
   end
  
  
end
